package com.xoa.controller.financialManage.charge;


import com.xoa.model.financialManage.charge.ChargeList;
import com.xoa.model.financialManage.charge.ChargeType;
import com.xoa.service.financialManage.charge.ChargeListService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 费用信息 前端控制器
 * </p>
 *
 * @author liujian
 * @since 2020-04-23
 */
@RestController
@RequestMapping("/chargeList")
public class ChargeListController {

    @Autowired
    ChargeListService chargeListService;

    //新增费用
    @RequestMapping("/saveChargeList")
    public ToJson saveChargeList(HttpServletRequest request, @RequestBody ChargeList chargeList){
        return chargeListService.save(request,chargeList);
    }

    //删除费用
    @RequestMapping("/delChargeList")
    public ToJson delChargeList(Integer chargeListId){
        return chargeListService.deleteById(chargeListId);
    }

    //编辑费用
    @RequestMapping("/editChargeList")
    public ToJson editChargeList(@RequestBody ChargeList chargeList){
        return chargeListService.update(chargeList);
    }

    //根据ID查询费用
    @RequestMapping("/findChargeListById")
    public ToJson editChargeList(Integer chargeListId){
        return chargeListService.selectById(chargeListId);
    }


    /**
     * 条件查询费用
     * @param request
     * @param deptId 部门ID
     * @param key 关键字(姓名，事由)
     * @param filter(1-本月,2-本周,3-今天,4-近三天,5-近一周,6-近一个月)
     * @param typeId 类型
     * @param undertaker 承担方式
     * @param year 年
     * @param month 月
     * @param day 日
     * @return
     */
    @RequestMapping("/conChargeList")
    public ToJson conChargeList(HttpServletRequest request , Integer deptId, String key ,String filter,Integer typeId,String undertaker, Integer year ,Integer month,Integer day){
        return chargeListService.conChargeList(request,deptId,key,filter,typeId,undertaker,year,month,day);
    }

    /**
     * 我的费用查询(时间-类型维度统计)
     * @param request
     * @param filter (year,quarter,month)默认按照年统计
     * @param year
     * @param month
     * @return
     */
    @RequestMapping("/findMyChargeList")
    @ResponseBody
    public ToJson findMyChargeList(HttpServletRequest request , Integer deptId, String filter, Integer year,Integer month){
        return chargeListService.findMyChargeList(request,deptId,filter,year,month);
    }


    /**
     * 费用统计
     * @return
     */
    @RequestMapping("/chargeStatistical")
    @ResponseBody
    public ToJson<ChargeType> chargeStatistical(HttpServletRequest request, @RequestParam("type") String type, Integer page, Integer limit){
        return chargeListService.chargeStatistical(request,type,page,limit);
    }

    /**
     * 查询所有明细
     * @param request
     * @param type（2部门，3用户）
     * @param id（如果是部门就传部门ID，如果是用户就传用户userID）
     * @param paymentDateSta（开始时间，查看细明用到）
     * @param paymentDateEnd（结束时间）
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/chargeDetail")
    @ResponseBody
    public ToJson<ChargeType> chargeDetail(HttpServletRequest request,
                                           @RequestParam("type") String type,
                                           @RequestParam("id") String id,
                                           String paymentDateSta,
                                           String paymentDateEnd,
                                           @RequestParam("settingId") String settingId,
                                           Integer page,
                                           Integer limit){
        return chargeListService.chargeDetail(request,type,id,paymentDateSta,paymentDateEnd,settingId,page,limit);
    }



}
